package com.mk.common;

import com.mk.model.entity.Tag;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;

/**
 * @Author: yq
 * @Description: 从xml中配置并导入文档包
 * @Date: Created in 4:24 PM 3/16/18
 */
public class XmlHelper {

    public static Tag parseXmlToTag(String path) throws DocumentException {
        SAXReader reader = new SAXReader();
        Document document = reader.read(new File(path));
        Element root = document.getRootElement();
        Tag tag = new Tag();
        tag.setNum(root.elementText(FileConfig.DIR_XML_NODES.num));
        tag.setPacId(Long.parseLong(root.elementText(FileConfig.DIR_XML_NODES.dirId)));
        tag.setTitle(root.elementText(FileConfig.DIR_XML_NODES.title));
        tag.setFname(root.elementText(FileConfig.DIR_XML_NODES.fname));
        tag.setModel(root.elementText(FileConfig.DIR_XML_NODES.model));
        tag.setAvator(root.elementText(FileConfig.DIR_XML_NODES.avator));
        tag.setVersion(root.elementText(FileConfig.DIR_XML_NODES.version));
        tag.setDes(root.elementText(FileConfig.DIR_XML_NODES.des));
        tag.setSkey(root.elementText(FileConfig.DIR_XML_NODES.key));
        return tag;
    }
}
